﻿Imports System.Data
Imports System.Data.SqlClient
Public Class ProvClienteDAO
    Implements ICliente

    Private connection As SqlConnection

    Public Sub New(ByVal connection As SqlConnection)
        Me.connection = connection
    End Sub

    Public Function CadastrarCliente(ByVal parCliente As SuporteModel.Cliente) As Boolean Implements ICliente.CadastrarCliente

    End Function

    Public Function ExcluirCliente(ByVal parIdCliente As Integer) As Boolean Implements ICliente.ExcluirCliente

    End Function

    Public Function ListarClientes() As System.Collections.Generic.List(Of SuporteModel.Cliente) Implements ICliente.ListarClientes
        Dim listaClientes As New List(Of SuporteModel.Cliente)
        Try
            Me.connection.Open()
            Dim comm As New SqlCommand("select CLI_CODIGO,CLI_NOME,CLI_INATIVO from CLIENTES where CLI_INATIVO = 1", Me.connection)
            Dim dataReader As SqlDataReader = comm.ExecuteReader()
            While dataReader.Read()
                Dim cliente As New SuporteModel.Cliente
                cliente.Codigo = Convert.ToInt64(dataReader("CLI_CODIGO"))
                cliente.Nome = dataReader("CLI_NOME").ToString()
                If Convert.ToInt64(dataReader("CLI_INATIVO")) > 0 Then
                    cliente.Inativo = True
                Else
                    cliente.Inativo = False
                End If
                listaClientes.Add(cliente)
            End While

        Catch ex As Exception
        Finally
            Me.connection.Close()
        End Try
        Return listaClientes
    End Function

    Public Function BuscarCliente(parIdCliente As Object) As SuporteModel.Cliente Implements ICliente.BuscarCliente
        Dim cliente As New SuporteModel.Cliente
        Try
            Me.connection.Open()
            Dim comm As New SqlCommand("select CLI_CODIGO,CLI_NOME,CLI_INATIVO from CLIENTES where CLI_INATIVO = 1", Me.connection)
            Dim dataReader As SqlDataReader = comm.ExecuteReader()
            If dataReader.Read() Then
                cliente.Codigo = Convert.ToInt64(dataReader("CLI_CODIGO"))
                cliente.Nome = dataReader("CLI_NOME").ToString()
                If Convert.ToInt64(dataReader("CLI_INATIVO")) > 0 Then
                    cliente.Inativo = True
                Else
                    cliente.Inativo = False
                End If
            End If
        Catch ex As Exception
        Finally
            Me.connection.Close()
        End Try
        Return cliente
    End Function
End Class
